#!/usr/bin/python
# -*- coding: utf-8 -*-
# coding: utf-8

import MySQLdb
import sys
from optparse import OptionParser
from getpass import getpass


parser = OptionParser()
parser.add_option("-s", "--serveur", dest="serveur", default="localhost", help="Adresse du serveur MySQL")
parser.add_option("-u", "--user", dest="user", default="root", help="Utilisateur MySQL")
parser.add_option("-d", "--database", dest="dbName", default="coMexpert", help="Base de données MySQL")    
parser.add_option("-l", "--len", dest="len", default="6", help="Longueur du champ")    

(options, args) = parser.parse_args()

try:
	a=int(options.len)
except ValueError:
	print "Le paramètre en doit être un entier !"
	sys.exit(1);

passWord=getpass()

	
db=MySQLdb.connect(options.serveur, options.user, passWord, options.dbName)
c=db.cursor()
c.execute("SET NAMES 'utf8'")
c.execute("SET CHARACTER SET utf8")

c.execute("ALTER TABLE client CHANGE code code VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE actionsClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE adressesClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE commentairesClient CHANGE codeClient codeClient VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE contactClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE documentsClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE echeancesClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE favorisClient CHANGE client client VARCHAR("+options.len+") DEFAULT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE materielsClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE prixArticleClient CHANGE client client VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE teteBLs CHANGE codeClient codeClient VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE teteCommandes CHANGE codeClient codeClient VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE teteDevis CHANGE codeClient codeClient VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE teteFactures CHANGE codeClient codeClient VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")
c.execute("ALTER TABLE tvaClient CHANGE codeClient codeClient VARCHAR("+options.len+") NOT NULL COMMENT 'Code du client'")

c.execute("ALTER TABLE prospect CHANGE code code VARCHAR("+options.len+") NOT NULL COMMENT 'Code du prospect'")
c.execute("ALTER TABLE client CHANGE prospect prospect VARCHAR("+options.len+") NOT NULL COMMENT 'Code du prospect'")
c.execute("ALTER TABLE contactProspect CHANGE prospect prospect VARCHAR("+options.len+") NOT NULL COMMENT 'Code du prospect'")
c.execute("ALTER TABLE documentsProspect CHANGE prospect prospect VARCHAR("+options.len+") NOT NULL COMMENT 'Code du prospect'")
c.execute("ALTER TABLE favorisProspect CHANGE prospect prospect VARCHAR("+options.len+") DEFAULT NULL  COMMENT 'Code du prospect'")
c.execute("ALTER TABLE teteDevis CHANGE codeProspect codeProspect VARCHAR("+options.len+") NOT NULL COMMENT 'Code du prospect'")
c.execute("ALTER TABLE tvaProspect CHANGE codeProspect codeProspect VARCHAR("+options.len+") NOT NULL COMMENT 'Code du prospect'")


c.close()